<html>
<head><meta charset="utf-8"><title>llvm static calling · t-compiler/help · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/index.html">t-compiler/help</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/llvm.20static.20calling.html">llvm static calling</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="186997228"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/llvm%20static%20calling/near/186997228" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/llvm.20static.20calling.html#186997228">(Jan 30 2020 at 15:25)</a>:</h4>
<p>If anyone here has thoughts on how to fix the problem described here: <a href="https://github.com/rust-lang/rust/pull/67502#issuecomment-580305566" target="_blank" title="https://github.com/rust-lang/rust/pull/67502#issuecomment-580305566">https://github.com/rust-lang/rust/pull/67502#issuecomment-580305566</a> I'd love to hear them</p>



<a name="186997308"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/llvm%20static%20calling/near/186997308" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/llvm.20static.20calling.html#186997308">(Jan 30 2020 at 15:26)</a>:</h4>
<p>the static is <code>static FOO: unsafe extern "C" fn(*mut u8) -&gt; ! = ...</code> fwiw</p>



<a name="186997382"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/llvm%20static%20calling/near/186997382" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/llvm.20static.20calling.html#186997382">(Jan 30 2020 at 15:27)</a>:</h4>
<p>Try inserting a load here: <a href="https://github.com/Mark-Simulacrum/rust/blob/opt-catch/src/librustc_codegen_ssa/mir/block.rs#L187" target="_blank" title="https://github.com/Mark-Simulacrum/rust/blob/opt-catch/src/librustc_codegen_ssa/mir/block.rs#L187">https://github.com/Mark-Simulacrum/rust/blob/opt-catch/src/librustc_codegen_ssa/mir/block.rs#L187</a></p>



<a name="186997558"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/llvm%20static%20calling/near/186997558" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/llvm.20static.20calling.html#186997558">(Jan 30 2020 at 15:28)</a>:</h4>
<p><span class="user-mention" data-user-id="143274">@Amanieu</span> so <code>bx.load_operand(bx.eh_unwind_resume()).immediate()</code>?</p>



<a name="186997619"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/llvm%20static%20calling/near/186997619" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/llvm.20static.20calling.html#186997619">(Jan 30 2020 at 15:29)</a>:</h4>
<p>maybe the problem is really with eh_unwind_resume itself, and the fallback case of the "declare_fn" being wrong now (since there's no such fn)</p>



<a name="186997880"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/llvm%20static%20calling/near/186997880" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/llvm.20static.20calling.html#186997880">(Jan 30 2020 at 15:32)</a>:</h4>
<p>Well you're definitely missing a load instruction. You can't call a static, you need to get the function pointer out of it first.</p>



<a name="186997929"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/llvm%20static%20calling/near/186997929" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/llvm.20static.20calling.html#186997929">(Jan 30 2020 at 15:33)</a>:</h4>
<p>hm, what does get_static do then?</p>



<a name="186997936"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/llvm%20static%20calling/near/186997936" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/llvm.20static.20calling.html#186997936">(Jan 30 2020 at 15:33)</a>:</h4>
<p>I'm not too familiar with the codegen API, so I can't really tell you what the correct method to use on <code>bx</code> is.</p>



<a name="186997937"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/llvm%20static%20calling/near/186997937" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/llvm.20static.20calling.html#186997937">(Jan 30 2020 at 15:33)</a>:</h4>
<p>i.e. what is it returning?</p>



<a name="186997951"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/llvm%20static%20calling/near/186997951" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/llvm.20static.20calling.html#186997951">(Jan 30 2020 at 15:33)</a>:</h4>
<p>A pointer to the static?</p>



<a name="186997962"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/llvm%20static%20calling/near/186997962" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/llvm.20static.20calling.html#186997962">(Jan 30 2020 at 15:33)</a>:</h4>
<p>oh, so I thought it was a load</p>



<a name="186997968"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/llvm%20static%20calling/near/186997968" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/llvm.20static.20calling.html#186997968">(Jan 30 2020 at 15:33)</a>:</h4>
<p>but I guess a pointer makes more sense</p>



<a name="186999343"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/llvm%20static%20calling/near/186999343" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/llvm.20static.20calling.html#186999343">(Jan 30 2020 at 15:47)</a>:</h4>
<p>It still looks wrong. The second half of <code>eh_unwind_resume</code> in <code>context.rs</code> declares <code>rust_eh_unwind_resume</code> as a function pointer if it can't find the lang item (which is the case when compiling libcore). You need to change that half to declare <code>rust_eh_unwind_resume</code> as a static and return a pointer to it.</p>



<a name="186999474"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/llvm%20static%20calling/near/186999474" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/llvm.20static.20calling.html#186999474">(Jan 30 2020 at 15:48)</a>:</h4>
<p>That way you can just have an unconditional load in <code>codegen_resume_terminator</code>.</p>



<a name="187026376"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/llvm%20static%20calling/near/187026376" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/llvm.20static.20calling.html#187026376">(Jan 30 2020 at 20:17)</a>:</h4>
<p>I think the code right now is correct, just "wrong" in the sense that it's not as nice as it could be, right? I'm thinking that unconditionally returning a function pointer from <code>eh_unwind_resume</code> is the right thing to do, and then we don't need a static, right?</p>



<a name="187026429"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/llvm%20static%20calling/near/187026429" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/llvm.20static.20calling.html#187026429">(Jan 30 2020 at 20:18)</a>:</h4>
<p>(in the second case)</p>



<a name="187028370"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/llvm%20static%20calling/near/187028370" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/llvm.20static.20calling.html#187028370">(Jan 30 2020 at 20:41)</a>:</h4>
<p>That won't work since the value is cached. You need to emit a load instruction at every use point.</p>



<a name="187028464"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/llvm%20static%20calling/near/187028464" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/llvm.20static.20calling.html#187028464">(Jan 30 2020 at 20:42)</a>:</h4>
<p>hm, right, that makes sense -- we can't stick a load instruction into nowhere, I guess?</p>



<a name="187028484"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/llvm%20static%20calling/near/187028484" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/llvm.20static.20calling.html#187028484">(Jan 30 2020 at 20:42)</a>:</h4>
<p>bit sad to have to load from memory every time, but I guess maybe the optimizer can optimize away the load too</p>



<a name="187028520"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/llvm%20static%20calling/near/187028520" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/llvm.20static.20calling.html#187028520">(Jan 30 2020 at 20:43)</a>:</h4>
<p>It should be able to optimize it away with LTO since the static is a constant.</p>



<a name="191655731"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/llvm%20static%20calling/near/191655731" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> eddyb <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/llvm.20static.20calling.html#191655731">(Mar 24 2020 at 18:46)</a>:</h4>
<p>is this done with weak linkage or something?</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>